import { ref,reactive, computed } from "vue"
import { useSearchStore } from "../../../../store/search"

export const useProjectDrawerHook = (emits: any) => {
  // const searchStore = useSearchStore()
  // searchStore.getDictDatas()
  // const

  const form = reactive({
    companyName: "",
    itemName: "",
    batchs: "",
    moneyStart: "",
    moneyEnd: "",
    itemTypes: []
  })
  const batchs = computed(()=>{
    const year = []
    const date = new Date();
      const currentYear = date.getFullYear();
      // year.push({ dictLabel: currentYear, dictValue: currentYear })
      for(var i=0;i<20;i++){
        year.push({ dictLabel: currentYear-i, dictValue: currentYear-i })
      }
    return year
  })
  const projectTypes = [
    { dictLabel: "专项资金", dictValue: "1" },
    { dictLabel: "荣誉资质", dictValue: "2" },
    { dictLabel: "赛事活动", dictValue: "3" },
    { dictLabel: "其他", dictValue: "4" }
  ]
  const companyName = ref('')
  const project = ref('')

  const query = (form1,pageSize4,currentPage4) => {
    // Processing form data
    // get keyword search type
    if (form.moneyStart > form.moneyEnd) {
      return ElMessage({
        type: "warning",
        message: "立项金额区间错误",
        grouping: true
      })
    }
    const params = {
      batchs: form.batchs ? form.batchs : [],
      itemTypes: form.itemTypes,
      companyName: form1.name?form1.name:form?.companyName,
      itemName: form.itemName,
      moneyStart:form.moneyStart,
      moneyEnd:form.moneyEnd,
      id:form1.id,
    }

    emits("queryProjectList", {params,pageSize4,currentPage4})

    // hightLight(form.companyName,scoped.row.incorporation)
    companyName.value = form.companyName
    project.value= form.itemName
  }

  const resetForm = () => {
    form.batchs = ""
    form.companyName = ""
    form.itemName = ""
    form.itemTypes = []
    form.moneyStart = ''
    form.moneyEnd = ''
    companyName.value = ''
    project.value = ''
    emits("queryProjectList", {})
  }
  const validateInput = (e: any, type: 1 | 2) => {
    // 使用正则表达式检查输入是否为正数（包括小数）
    switch (type) {
      case 1:
        form.moneyStart = e.replace(/[^0-9.]+/, "")
        break;
      case 2:
        form.moneyEnd = e.replace(/[^0-9.]+/, "")
        break;
    }

  }

  return { form, query, resetForm, projectTypes, validateInput,companyName,project,batchs }
}
